﻿using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Net.Configuration;
using System.Web;
using System.Web.Configuration;
using ABC.Core.Utilities;
using IApplicationSettingsProvider = ABC.Core.Providers.IApplicationSettingsProvider;

namespace ABC.Web.Providers
{
    public class ApplicationSettingsProvider : IApplicationSettingsProvider
    {
        public string StatusCacheConnectionString
        {
            get
            {
                var setting = ConfigFileConnections[Lambda.Property<IApplicationSettingsProvider>(x => x.StatusCacheConnectionString)];
                return setting.ConnectionString;
            }
        }

        public string VirtualImagePath
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.VirtualImagePath)];
                return setting;
            }
        }

        public string VirtualScriptPath
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.VirtualScriptPath)];
                return setting;
            }
        }

        public string VirtualStylePath
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.VirtualStylePath)];
                return setting;
            }
        }

        public string MemoryCacheHost
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.MemoryCacheHost)];
                return setting;
            }
        }

        public string UserNameCallCenter
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.UserNameCallCenter)];
                return setting;
            }
        }

        public int MemoryCacheDb
        {
            get
            {
                var setting = Convert.ToInt32(ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.MemoryCacheDb)]);
                return setting;
            }
        }

        public int MemoryCachePoolSize
        {
            get
            {
                var setting = Convert.ToInt32(ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.MemoryCachePoolSize)]);
                return setting;
            }
        }

        public TimeSpan MemoryCacheTimeout
        {
            get
            {
                var setting = TimeSpan.Parse(ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.MemoryCacheTimeout)]);
                return setting;
            }
        }

        public TimeSpan MemoryCacheActivityTimeout
        {
            get
            {
                var setting = TimeSpan.Parse(ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.MemoryCacheActivityTimeout)]);
                return setting;
            }
        }

        public TimeSpan MemoryCacheGuestTimeout
        {
            get
            {
                var setting = TimeSpan.Parse(ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.MemoryCacheGuestTimeout)]);
                return setting;
            }
        }

        public TimeSpan MemoryCacheUserRatingsTimeout
        {
            get
            {
                var setting = TimeSpan.Parse(ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.MemoryCacheUserRatingsTimeout)]);
                return setting;
            }
        }

        public TimeSpan MemoryCacheUserGiftTimeout
        {
            get
            {
                var setting = TimeSpan.Parse(ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.MemoryCacheUserGiftTimeout)]);
                return setting;
            }
        }

        public string GoogleOAuthConsumerKey
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.GoogleOAuthConsumerKey)];
                return setting;
            }
        }

        public string GoogleOAuthConsumerValue
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.GoogleOAuthConsumerValue)];
                return setting;
            }
        }

        private static NameValueCollection ConfigFileSettings
        {
            get
            {
                return WebConfigurationManager.AppSettings;
            }
        }

        private static ConnectionStringSettingsCollection ConfigFileConnections
        {
            get
            {
                return WebConfigurationManager.ConnectionStrings;
            }
        }

        public SmtpSection SmtpMailSettings
        {
            get
            {
                var config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
                var mailSettings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
                return mailSettings.Smtp;
            }
        }
        public string VkApplicationId
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.VkApplicationId)];
                return setting;
            }
        }

        public string VkSecretKey
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.VkSecretKey)];
                return setting;
            }
        }

        public string YandexMetrikaId
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.YandexMetrikaId)];
                return setting;
            }
        }

        public string YandexDiskToken
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.YandexDiskToken)];
                return setting;
            }
        }

        public string DirectionToLeaveServerUrl
        {
            get
            {
                var setting = ConfigFileSettings[Lambda.Property<IApplicationSettingsProvider>(x => x.DirectionToLeaveServerUrl)];
                return setting;
            }
        }
    }
}